﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NHModel.Entities;
using NHBLL;
using StudyWeb.Common;

namespace StudyWeb.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        //public ActionResult Index()
        //{
        //    ViewData["Message"] = "Welcome to ASP.NET MVC!";

        //    return View();            
        //}

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Index()
        {
            return RedirectToAction("Index1", "Home");
        }
        public ActionResult Index1()
        {
            MsgContent item = new MsgContent();
            item.Eamil = new MsgEmail();
           
            return View(item);
        }

        [HttpPost]
        public ActionResult Index1(string UEmail, string Msg)
        {
            if (string.IsNullOrEmpty(UEmail))
            {
                ViewData["Msg1"] = "邮箱不能为空";
                return View();
            }
            if (CommonMethods.IsEmail(UEmail))
            {
                ViewData["Msg1"] = "Email格式不正确";
                return View();
            }
            MsgEmail Eitem = new MsgEmail();
            Eitem.UEmail = UEmail;
            bool IsSuccess = MsgContentService.Add(Eitem);
            MsgContent item = new MsgContent();
            item.CreateTime = DateTime.Now;
            item.Msg = Msg;
            item.Eamil = Eitem;            
            IsSuccess = MsgContentService.Add(item);
            if (IsSuccess)
            {
                ViewData["Msg1"] = "以收到您的留言，请注意查收我们给您发送的邮件回复，感谢您的关注。";
            }
            else
                ViewData["Msg1"] = "添加失败";
            return View();
        }

    }
}
